<?php
// Library File
include 'lib/library.php';

// URL address
$addr = address();

// Local address
$rel_addr = relative_address();

// Database Connection
include $rel_addr.'/lib/mysql_connect.inc';

// Header File
include $rel_addr.'/lib/header.php';

// Footer File
include $rel_addr.'/lib/footer.php';


$profile_id = $_GET['id'];

		/*
		**   G E T    V A R S
		*/
		$query = mysql_query("SELECT * FROM users WHERE user_id='$profile_id'");
		$id_exists = mysql_num_rows($query);
		
		if((isset($profile_id) && !$id_exists) || !isset($profile_id)){
			refresh('/index.php');
		}else{
			$user_array = mysql_fetch_array($query);
		}
		
		$query = mysql_query("SELECT * FROM profiles where user_id='$profile_id'");
		$profile_array = mysql_fetch_array($query);

		$title = "{$user_array['name']}'s Profile";
		$subtitle = "{$user_array['name']}'s Profile";
		
		if(!empty($user_array['name'])){
		
			// Creates an image of the email address of the user be viewed
			include $rel_addr.'/scripts/emailtopicture.php';
		
			$content .= '
				<ul class="profile">
			';
			
			// Member type
			$var = 'Member Type';
			switch ($user_array['member_type']){
				
				case 'IND':
					$content .='
					<li><h1>'.$var.':</h1> Individual</li>
					';
					break;
				case 'ORG':
					$content .='
					<li><h1>'.$var.':</h1> Non-Profit Organization</li>
					';
					break;
				case 'BUS':
					$content .='
					<li><h1>'.$var.':</h1> Business</li>
					';
					break;
			}
				
			// Email
			if($profile_array['email']){
				$content .='
					<li><h1>Email:</h1> <img src="'.$addr.'/images/'.$m_user_id.$profile_id.'.png" title="Emails are images to protect you from spam" /></li>
				';
			}
			
			// Website
			if($profile_array['website'] && !empty($user_array['website'])){
				$content .='
				<li><h1>Website:</h1> '.$user_array['website'].'</li>
				';
			}
			
			// Birthday
			if($profile_array['birthday']){
				$content .='
					<li><h1>Birthday:</h1> '.$user_array['birthday'].'</li>
				';
			}
			
			// Gender
			if($profile_array['gender']){
				$content .='
					<li><h1>Gender:</h1> '.$user_array['gender'].'</li>
				';
			}
			
			// Phone number
			if($profile_array['phone_number']){
				$content .='
					<li><h1>Phone Number:</h1> '.$user_array['phone_number'].'</li>
				';
			}
			
			// Address line 1
			if($profile_array['address_line1']){
				$content .='
					<li><h1>Address:</h1> '.$user_array['address_line1'].'</li>
				';
			}
			
			if($profile_array['address_line2'] && !empty($user_array['address_line2'])){
				// Address line 2
				$content .='
					<li><h1>Address:</h1> '.$user_array['address_line2'].'</li>
				';
			}
			
			// City
			if($profile_array['city']){
				$content .='
					<li><h1>City:</h1> '.$user_array['city'].'</li>
				';
			}
			
			// State
			if($profile_array['state']){
				$content .='
					<li><h1>State:</h1> '.$user_array['state'].'</li>
				';
			}
			
			// Zipcode
			if($profile_array['zipcode']){
				$content .='
					<li><h1>Zipcode:</h1> '.$user_array['zipcode'].'</li>
				';
			}
			
			$content .= '
				</ul>
			';
			
				/*
				**   P R O F I L E
				**      S E S S I O N
				*/
				session_name("Profile");
				session_start();
				$_SESSION['p_img'] = $rel_addr.'/images/'.$m_user_id.$profile_id.'.png';
				$_SESSION['p_on_profile'] = true;
				$_SESSION['p_profile_id'] = $profile_id;
		
		}

/*
**   P U T    V A R S
**    O N    P A G E
*/
	top($title,$style);
	middle($header,$subtitle,$content);
	bottom($navigation,$footer,$dbc);
?>
